﻿namespace leastsquare
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // 设置一个年份链表
            List<double> listyear = new List<double>();
            //输入年份
            for (int year = 2020; year >=2006; year--)
            {
                listyear.Add(year);
            }
            //转成数组
            double[] list = listyear.ToArray();
            // 求平均年份
            double ayear = listyear.Average();
            //gdp数组
            double[] gdp =
            {
                14687673892882,
                14279937500608,
                13894817549380,
                12310409370894,
                11233276536744,
                11061553079871,
                10475682920597,
                9570406235659,
                8532229986993,
                7551500124197,
                6087163874510,
                5101703073088,
                4594307032667,
                3550342737009,
                2752131773358
            };
            //gdp平均值
            double agdp = gdp.Average();
            // 求b
            double b = getab.getb(list, gdp, ayear, agdp);
            // 求a
            double a = getab.geta(ayear, agdp, b);
            Console.WriteLine("请输入年份");
            double x = Convert.ToDouble(Console.ReadLine());
            double result = b * x + a;
            Console.Write("{0}年的预测值为：{1}", x, result);
            var m =Console.ReadKey();
        }
    }
}